/*
 * Copyright (c) 2020, 2025, keyila All rights reserved.
 *
 */
package com.clp.bean;

import lombok.Data;

import java.io.Serializable;

/**
 * @author clp
 * @version 1.0
 */
@Data
public class Result<T> implements Serializable {

    private Result(){}

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static Result ok(){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        return result;
    }

    public static Result ok(Integer resultCode,String resultMessage){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;
    }

    public static<T> Result ok(Integer resultCode,String resultMessage,T data){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

    public static<T> Result ok(T data){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result fail(){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        return result;
    }

    public static Result fail(Integer resultCode,String resultMessage){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;
    }

    public static<T> Result fail(Integer resultCode,String resultMessage,T data){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

    public static<T> Result fail(T data){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        result.setData(data);
        return result;
    }



}
